/**
 * 同时支持web/mini
 *  */

 import {storage_prefix,env} from './config'

 const set=env==='web'?localStorage.setItem:wx.setStorageSync
 const get=env==='web'?localStorage.getItem:wx.getStorageSync
 const remove=env==='web'?localStorage.removeItem:wx.removeStorageSync

 const commonStorage={
     get(){
         return key=>get(storage_prefix+key)?(env==='web'?JSON.parse(get(storage_prefix+key)):get(storage_prefix+key)):null
     },
     set(){
        return (key,val)=>set(storage_prefix+key,env==='web'?JSON.stringify(val):val) 
     },
     remove(){
         return key=>remove(storage_prefix+key)
     }
 }

 export const getStorage=commonStorage.get()

 export const setStorage=commonStorage.set()
 
 export const removeStorage=commonStorage.remove()
  